package offer;

class solution04 {
    public static boolean findNumberIn2DArray(int[][] matrix, int target) {
        int i, j;
        boolean flag = false;
        for (i = 0; i < matrix[i].length; i++) {
            if (target >= matrix[i][0] && target <= matrix[i][matrix[i].length-1]) {
                flag = true;
                break;
            }
        }
        if (flag == false) {
            return false;
        }
        for (j = 0; j < matrix[i].length; j++) {
            if (target == matrix[i][j]) {
                return true;
            }
        }
        return false;
    }


    public static void main(String[] args) {
         int [][]matrix1 = {{1,4,7,11,15},
                            {2,5,8,12,19},
                            {3,6,9,16,22},
                            {10,13,14,17,24},
                            {18,21,23,26,30}};
         findNumberIn2DArray(matrix1,10);
    }

}
